package com.itheima.text1;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

public class UDPReceive {
    public static void main(String[] args) throws IOException {
        DatagramSocket socket = new DatagramSocket(10001);


            byte[] bytes = new byte[1024];

            DatagramPacket packet = new DatagramPacket(bytes, bytes.length);

            socket.receive(packet);
            //获取发送端ip
            InetAddress address = packet.getAddress();
            String ip = address.getHostAddress();

            int length = packet.getLength();

            String s = new String(bytes, 0, length);

            System.out.println(ip + " :" + s);

       // socket.close();
    }
}
